"""
营销 - 营销活动查询模型
"""

from typing import Dict, Any, List
from jlpay.model.base import OrgBaseReq, BaseResponse


class MarketingActivityQueryRequest(OrgBaseReq):
    """营销活动查询请求"""
    
    def __init__(self):
        """初始化营销活动查询请求"""
        super().__init__()
        self.sponsor_id = None  # 赞助商ID
        self.page = None  # 页码
        self.limit = None  # 每页数量限制
    
    def set_sponsor_id(self, sponsor_id: str):
        """
        设置赞助商ID
        
        Args:
            sponsor_id: 赞助商ID
            
        Returns:
            MarketingActivityQueryRequest实例
        """
        self.sponsor_id = sponsor_id
        return self
    
    def set_page(self, page: str):
        """
        设置页码
        
        Args:
            page: 页码
            
        Returns:
            MarketingActivityQueryRequest实例
        """
        self.page = page
        return self
    
    def set_limit(self, limit: str):
        """
        设置每页数量限制
        
        Args:
            limit: 每页数量限制
            
        Returns:
            MarketingActivityQueryRequest实例
        """
        self.limit = limit
        return self
    
    def path(self) -> str:
        """
        获取接口路径
        
        Returns:
            接口路径
        """
        return "/open/org/bank/act-bridge/act/list/sponsor"
    
    def to_dict(self) -> Dict[str, Any]:
        """
        将请求对象转换为字典，过滤掉值为None的字段
        
        Returns:
            字典对象
        """
        return {k: v for k, v in self.__dict__.items() if not k.startswith('_') and v is not None}


class MarketingActivityData:
    """营销活动数据"""
    
    def __init__(self):
        """初始化营销活动数据"""
        self.act_id = None  # 活动ID
        self.act_name = None  # 活动名称
        self.sponsor_id = None  # 赞助商ID
        self.sponsor_name = None  # 赞助商名称
        self.start_time = None  # 活动开始时间
        self.end_time = None  # 活动结束时间
        self.status = None  # 活动状态
        self.act_type = None  # 活动类型
        self.create_time = None  # 创建时间
        self.update_time = None  # 更新时间
    
    def set_act_id(self, act_id: str):
        """设置活动ID"""
        self.act_id = act_id
        return self
    
    def set_act_name(self, act_name: str):
        """设置活动名称"""
        self.act_name = act_name
        return self
    
    def set_sponsor_id(self, sponsor_id: str):
        """设置赞助商ID"""
        self.sponsor_id = sponsor_id
        return self
    
    def set_sponsor_name(self, sponsor_name: str):
        """设置赞助商名称"""
        self.sponsor_name = sponsor_name
        return self
    
    def set_start_time(self, start_time: str):
        """设置活动开始时间"""
        self.start_time = start_time
        return self
    
    def set_end_time(self, end_time: str):
        """设置活动结束时间"""
        self.end_time = end_time
        return self
    
    def set_status(self, status: str):
        """设置活动状态"""
        self.status = status
        return self
    
    def set_act_type(self, act_type: str):
        """设置活动类型"""
        self.act_type = act_type
        return self
    
    def set_create_time(self, create_time: str):
        """设置创建时间"""
        self.create_time = create_time
        return self
    
    def set_update_time(self, update_time: str):
        """设置更新时间"""
        self.update_time = update_time
        return self
    
    def to_dict(self) -> Dict[str, Any]:
        """
        将对象转换为字典
        
        Returns:
            字典对象
        """
        return {k: v for k, v in self.__dict__.items() if v is not None}


class MarketingActivityQueryResponse(BaseResponse):
    """营销活动查询响应"""
    
    def __init__(self, response_dict=None):
        """
        初始化营销活动查询响应
        
        Args:
            response_dict: 响应字典
        """
        super().__init__(response_dict)
        self.data = []  # 活动数据列表
        
        if response_dict and 'data' in response_dict:
            if isinstance(response_dict['data'], list):
                self.data = [MarketingActivityData() for _ in response_dict['data']]
                for i, item in enumerate(response_dict['data']):
                    for key, value in item.items():
                        if hasattr(self.data[i], f'set_{key}'):
                            getattr(self.data[i], f'set_{key}')(value)
    
    def to_dict(self) -> Dict[str, Any]:
        """
        将响应对象转换为字典
        
        Returns:
            字典对象
        """
        data = super().to_dict()
        if self.data:
            data['data'] = [item.to_dict() for item in self.data]
        return data 